# pip install zhipuai 请先在终端进行安装
import os

from zhipuai import ZhipuAI

client = ZhipuAI(api_key=os.environ["ZHIPU_API_KEY"])

response = client.chat.completions.create(
    model="glm-3-turbo",
    messages=[
        {
            "role": "system",
            "content": "您是一名计算机专家。"
        }
    ],
    top_p=0.7,
    temperature=0.95,
    max_tokens=1024,
    stream=True,
)
for trunk in response:
    print(trunk.choices[0].delta.content, end="")
